package com.jiajia.testclouduser.controller;

import com.jiajia.testclouduser.entity.BaseResult;
import com.jiajia.testclouduser.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private SessionUtil sessionUtil;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public BaseResult getLogin(HttpSession session) {
        BaseResult result = new BaseResult();
        session.setAttribute("msg", "收到了一条消息910921");
        result.setCode(BaseResult.OK);
        result.setData(session.getId());
        return result;
    }

    @RequestMapping(value = "/getSession", method = RequestMethod.GET)
    public BaseResult getSeesoin(@RequestParam("sessionId") String sessionId) {

        BaseResult result = new BaseResult();
        result.setCode(BaseResult.OK);
        result.setData(sessionId);
        Map<Object, Object> map=sessionUtil.getSessionMap(sessionId);
        result.setMessage((String) sessionUtil.getAttribute(sessionId, "msg"));
        return result;
    }


}
